
package com.graphite.task;

import com.graphite.client.GraphiteNettyClient;
import com.graphite.http.FetchGraphite;
import com.graphite.model.BaseRequest;
import com.graphite.model.BaseResponse;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

import java.util.concurrent.Callable;

/**
 * 拉取graphite数据任务线程封装类
 * @param <K>
 * @param <V>
 */
public class FetchGraphiteRequestTask<K extends BaseRequest, V extends BaseResponse> implements Callable<V> {
    private static Logger logger = LoggerFactory.getLogger(FetchGraphiteRequestTask.class);
    private K k;

    public FetchGraphiteRequestTask() {
    }

    public FetchGraphiteRequestTask(K reqeust){
        this.k = reqeust;
    }

    public void setRequestParameter(K k) {
        this.k = k;
    }

    public K getRequestParameter() {
        return this.k;
    }

    public V call() throws Exception {
        long startTime = System.currentTimeMillis();
        FetchGraphite<K, V> fetchGraphite = new GraphiteNettyClient();
        V vList = fetchGraphite.fetchData(this.k);
        long endTime = System.currentTimeMillis();
        logger.info("FetchGraphiteTask请求性能数据耗时（毫秒）：" + (endTime - startTime));
        return vList;
    }
}
